﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ChartLibrary;
using ChartLibrary.Base;
using ChartLibrary.Charts;

namespace TestApplication
{
    public partial class Page : UserControl
    {
        Random r;
        int i = 0;

        public Page()
        {
            InitializeComponent();
            ChartLibrary.Data.DataSource dm01, dm02, dm03;

            r = new Random(5478912);

            ChartLibrary.Charts.LineChart l = new ChartLibrary.Charts.LineChart();
            

            dm01 = cht.Data.Add("Datasource1");
            dm02 = cht.Data.Add("Datasource2");
            dm03 = cht.Data.Add("Datasource3");
            //dm04 = cht.Data.Add("Fancy Source");

            cht.ItemType = ItemType.PointTriangle;

            dm01.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
            dm02.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
            dm03.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));

            LinearGradientBrush lgr = new LinearGradientBrush();
            lgr.StartPoint = new Point(0, 0.5);
            lgr.EndPoint = new Point(1, 0.5);

            lgr.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 111, 206, 242), Offset = 0.0 });
            lgr.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 11, 95, 126), Offset = 0.499 });
            lgr.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 32, 98, 122), Offset = 0.5 });
            lgr.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 143, 222, 251), Offset = 1.0 });

            //dm01.Fill = lgr;

            dm01.AddRange(new double[] { 11, 22, 44, 55, 33 });
            dm02.AddRange(new double[] { 33, 21, 66, 22, 11 });
            dm03.AddRange(new double[] { 4, 29, 17, 33, 32 });
            //dm04.AddRange(new double[] { 44, 77, 21});


            dm01[0].XAxisValue = "Hello X-World";
            dm01[4].XAxisValue = "Hello Y-World";

            cmd.Click += new RoutedEventHandler(cmd_Click);
            cmd2.Click += new RoutedEventHandler(cmd2_Click);

            cmd3.Click += new RoutedEventHandler(cmd3_Click);
            cmd4.Click += new RoutedEventHandler(cmd4_Click);

            cmd5.Click += new RoutedEventHandler(cmd5_Click);
            cmd6.Click += new RoutedEventHandler(cmd6_Click);

            cht.ItemType = ItemType.PointTriangle;
            cht.Animation = Animation.FxRiseUpAsynchronous;

            //PointLineChart tmp = (PointLineChart)cht;

            //tmp.ItemClicked += new ItemHandler(tmp_ItemClicked);
            //tmp.ItemMouseEnter += new ItemHandler(tmp_ItemMouseEnter);
            //tmp.ItemMouseLeave += new ItemHandler(tmp_ItemMouseLeave);
        }

        void tmp_ItemMouseLeave(object sender, ItemEventArgs e)
        {
            
        }

        void tmp_ItemMouseEnter(object sender, ItemEventArgs e)
        {
            
        }

        void tmp_ItemClicked(object sender, ItemEventArgs e)
        {
            
        }

        void cht_ItemChanged()
        {
            
        }

        void cmd6_Click(object sender, RoutedEventArgs e)
        {
            //AxisCharts l = (AxisCharts)cht;
            //l.DisplayAxisNumbers = !l.DisplayAxisNumbers;

            //if (l.XAxisLines > 0) l.XAxisLines -= 1;
            //if (l.YAxisLines > 0) l.YAxisLines -= 1;
        }

        void cmd5_Click(object sender, RoutedEventArgs e)
        {
            //AxisCharts l = (AxisCharts)cht;

            //if (l.DisplayAxisLabel)
            //{
            //    l.DisplayAxisLabel = !l.DisplayAxisLabel;
            //    l.XLabel = "X Axis Label";
            //    l.YLabel = "Y Axis Label";
            //}


            //l.XAxisLines += 1;
            //l.YAxisLines += 1;
        }

        void cmd4_Click(object sender, RoutedEventArgs e)
        {
            cht.Width += 30;
            cht.Height += 30;
        }

        void cmd3_Click(object sender, RoutedEventArgs e)
        {
            switch (i)
            {
                case 0:
                    {
                        cht.Legend.DisplayType = DisplayType.Text;
                        cht.Legend.Layout = Layout.Horizontal;
                        break;
                    }
                case 1:
                    {
                        cht.Legend.DisplayType = DisplayType.TextAndLine;
                        cht.Legend.Layout = Layout.Horizontal;
                        break;
                    }
                case 2:
                    {
                        cht.Legend.DisplayType = DisplayType.Text;
                        cht.Legend.Layout = Layout.Vertical;
                        break;
                    }
                case 3:
                    {
                        cht.Legend.DisplayType = DisplayType.TextAndLine;
                        cht.Legend.Layout = Layout.Vertical;
                        break;
                    }
            }

            if (i == 3) i = 0;
            else i++;
        }

        void cmd2_Click(object sender, RoutedEventArgs e)
        {

            LinearGradientBrush lgr = new LinearGradientBrush();
            GradientStop gs1 = new GradientStop();
            gs1.Color = Color.FromArgb((byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255));
            gs1.Offset = 0;

            GradientStop gs2 = new GradientStop();
            gs2.Color = Color.FromArgb((byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255));
            gs2.Offset = 1;

            LinearGradientBrush lgr2 = new LinearGradientBrush();
            GradientStop gs3 = new GradientStop();
            gs3.Color = Color.FromArgb((byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255));
            gs3.Offset = 0;

            GradientStop gs4 = new GradientStop();
            gs4.Color = Color.FromArgb((byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255));
            gs4.Offset = 1;

            lgr.GradientStops.Add(gs1);
            lgr.GradientStops.Add(gs2);

            lgr2.StartPoint = new Point(0.5, 0);
            lgr2.EndPoint = new Point(0.5, 1);
            lgr2.GradientStops.Add(gs3); 
            lgr2.GradientStops.Add(gs4);

            cht.Legend.Background = lgr;
            cht.Background = lgr2;
        }

        void cmd_Click(object sender, RoutedEventArgs e)
        {
            cht.Title = "My Chart";
            cht.DisplayTitle = !cht.DisplayTitle;

            cht.FontSettings.TitleSize = 72;
            cht.Legend.Layout = Layout.Horizontal;
            cht.Legend.DisplayType = DisplayType.Text;
            cht.DisplayLegend = !cht.DisplayLegend;
        }
    }
}
